﻿using Models.Common;
using Models.MVC;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

namespace Web.Common
{
    public class BillCommon
    {
        public static Result<decimal> JiaoFuEditAsync(int BillNameID,int IndexID, decimal Qty, int ID = 0, string Remark = "", string Number = "", int IsExec = 0, string CreateTime = "",decimal HQty=0)
        {
            if (String.IsNullOrWhiteSpace(CreateTime))
            {
                CreateTime = DateTime.Now.ToString("yyyy-MM-dd");
            }
            Result<decimal> result = new Result<decimal>() { Type = AjaxResultType.Success, Content = "成功", Data = 0, TotalRows = 0 };
            try
            {
                SqlParameter[] paras ={
                    new SqlParameter("@ID",SqlDbType.Int),
                    new SqlParameter("@BillNameID",SqlDbType.Int),
                    new SqlParameter("@IndexID",SqlDbType.Int),
                    new SqlParameter("@Qty",SqlDbType.Money),
                    new SqlParameter("@HQty",SqlDbType.Money),
                    new SqlParameter("@Remark",SqlDbType.NVarChar,4000),
                    new SqlParameter("@Number",SqlDbType.NVarChar,4000),
                    new SqlParameter("@IsExec",SqlDbType.Int),
                    new SqlParameter("@CreateTime",SqlDbType.DateTime),
                    new SqlParameter("@Str",SqlDbType.NVarChar,4000),
                    new SqlParameter("@ReturnValue", SqlDbType.Int)
                                       };
                paras[0].Value = ID;
                paras[1].Value = BillNameID;
                paras[2].Value = IndexID;
                paras[3].Value = Qty;
                paras[4].Value = HQty;
                paras[5].Value = Remark;
                paras[6].Value = Number;
                paras[7].Value = IsExec;
                paras[8].Value = CreateTime;
                paras[9].Value = "";
                paras[9].Direction = ParameterDirection.InputOutput;
                paras[10].Direction = ParameterDirection.ReturnValue;

                DataSet ds = FreeADO.DBUtility.DbHelperSQL.RunProcedure("SP_JiaoFuEdit", paras, "aaa", 3000);
                if (Convert.ToInt32(paras[10].Value) == 1)
                {
                    result.Type = AjaxResultType.Success;
                    result.Content = "成功";
                    result.Data = 0;
                }
                else if (Convert.ToInt32(paras[10].Value) == -1)
                {
                    result.Type = AjaxResultType.Warning;
                    result.Content = paras[9].Value.ToString();
                    result.Data = 0;
                }
                else
                {
                    result.Type = AjaxResultType.Error;
                    result.Content = paras[9].Value.ToString();
                    result.Data = 0;
                }
            }
            catch (Exception e)
            {
                result.Type = AjaxResultType.Error;
                result.Content = e.Message;
                result.Data = 0;
            }
            return result;
        }
    }
}